package main

import (
	"fmt"
	"time"
)

//创建 chan  使用chan 接收chan带来的数据
func createWorker(id int) chan<- int {
	c := make(chan int)
	go func() {
		fmt.Printf("word %d received %c\n", id, <-c)
	}()
	return c
}
func chanDemo() {

	var channels [10]chan<- int

	for i := 0; i < 10; i++ {
		channels[i] = createWorker(i)
	}

	//向管道写数据
	for i := 0; i < 10; i++ {
		channels[i] <- 'a' + i
	}

	for i := 0; i < 10; i++ {
		channels[i] <- 'A' + i
	}

	time.Sleep(time.Millisecond)
}

func main() {
	chanDemo()
}
